import tkinter as tk
import tkinter.filedialog

#微信公众号：图控大叔
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

def get_file_path():
    selectFileName = tk.filedialog.askopenfilename(title='选择文件')
    if selectFileName.endswith(".xls"):
        print(".xls")
        path_name_label.config(text=selectFileName)
    elif selectFileName.endswith(".xlsx"):
        print(".xlsx")
        path_name_label.config(text=selectFileName)
    else:
        print("文件出错")
        path_name_label.config(text="文件格式可能不对，请选择.xls或者.xlsx")

def query_keyword():
    key_text = str(keyword_Text.get(0.0, tk.END))
    key_text = key_text.strip()
    if key_text.strip() == '':
        print("kon")
        query_keyword_ret_label.config(text="请输入数据")
    else:
        print(key_text)
        query_keyword_ret_label.config(text="结果：存在")

def create_new_file():
    query_create_new_file_ret_label.config(text="新建结果：已经新建")

def create_new_sheet_and_copy_data():
    create_new_sheet_ret_label.config(text="已经添加该sheet表，请等待")
    print("hhhh")

def tet():
    # ff = b1.cget("text")
    ff = str(sheet_name_Text.get(0.0,tk.END))
    ff = ff.strip()
    if ff == '':
        print("空")
    else:
        print(ff)

top = tk.Tk()

top.title("Excel自动化办公助手")
top.minsize(800, 400) #宽、高
# top.maxsize(1000, 400)


path_label = tk.Label(top, text="原文件名:", height=2, width=10, fg="blue", font=8)
path_label.place(x=2, y=2)  #x 横  y 纵
path_name_label = tk.Label(top, text="请选择后缀为.xls或者.xlsx格式的文件", height=2, width=100, fg="blue", anchor="w", font=8) #anchor：对齐方式 可选内容包括 n:靠上 w靠左 s靠下 e靠右 或者组合使用，，如nw 左上方对齐
path_name_label.place(x=100, y=2)
get_raw_file_btn = tk.Button(top, text="选择原文件", command=get_file_path, font=8)
get_raw_file_btn.place(x=12, y=44)

titil_keyword_label = tk.Label(top, text="行头关键字:", height=2, width=10, fg="blue", font=8)
titil_keyword_label.place(x=8, y=80)
keyword_Text=tk.Text(top, width=50, height=1, font=8)
keyword_Text.place(x=130, y=93)

query_keyword_btn = tk.Button(top, text="查询该关键字", command=query_keyword, font=8)
query_keyword_btn.place(x=12, y=124)
query_keyword_ret_label = tk.Label(top, text=" ", height=2, width=50, fg="blue", anchor="w", font=8)
query_keyword_ret_label.place(x=160, y=120)  #x 横  y 纵

query_create_new_file_label = tk.Label(top, text="是否新建同路径下excel文件？（文件命名由系统认定）", height=2, width=100, fg="blue", anchor="w", font=8)
query_create_new_file_label.place(x=8, y=160)
create_new_file_btn = tk.Button(top, text="新建", command=create_new_file, font=8)
create_new_file_btn.place(x=12, y=200)
query_create_new_file_ret_label = tk.Label(top, text=" ", height=2, width=50, fg="blue", anchor="w", font=8)
query_create_new_file_ret_label.place(x=80, y=195)

query_create_new_sheet_label = tk.Label(top, text="是否新建上一步骤excel文件中sheet表名？（表名由用户自拟）", height=2, width=100, fg="blue", anchor="w", font=8)
query_create_new_sheet_label.place(x=8, y=235)
titil_sheet_label = tk.Label(top, text="如果是，请输入sheet表名，该表名将作为关键字对原excel文件数据进行查询", height=2, width=100, fg="blue", anchor="w", font=8)
titil_sheet_label.place(x=8, y=270)
sheet_name_Text=tk.Text(top,width=50, height=1, font=8)
sheet_name_Text.place(x=12, y=310)
create_new_sheet_btn = tk.Button(top, text="新建sheet表", command=create_new_sheet_and_copy_data, font=8)
create_new_sheet_btn.place(x=12, y=345)
create_new_sheet_ret_label = tk.Label(top, text=" ", height=2, width=50, fg="blue", font=8, anchor="w")
create_new_sheet_ret_label.place(x=160, y=340)  #x 横  y 纵

top.mainloop()